-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Release 2.0 #19
base: main
Are you sure you want to change the base?
Release 2.0 #19
Conversation
Prashant-7718
commented
Feb 10, 2025
- Local code edit and preview
- Panel control options : zoom in out, pan
- Syntax highlighting
- vscode theme for mermaid light and dark
- Commands: Logout, login
- Right click menu option : Preview Diagram
- Global settings for theme
- code lenses integration with Aux files : .htm, md, .hugo
- Automatic connect to mermaid chart
- key binding for cnt + s or cmd + s for saving diagram to mermaid chart and local
"aliases": [ | ||
"Mermaid Flowchart", | ||
"mermaid flowchart" | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need the aliases in both cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it is not really needed but it is good to keep to avoid edge cases where Other VSCode extensions might refer to the language using different casing.
package.json
Outdated
"command": "mermaidChart.editMermaidChart", | ||
"title": "Edit Diagram in Mermaid chart" | ||
}, | ||
{ | ||
"command": "mermaidChart.editLocally", | ||
"title": "Edit Diagram" | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't these two need the MermaidChart:
prefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, these commands are not exposed to users, so they do not need the MermaidChart: prefix. Instead, I have removed them from package.json
"vite": "^6.0.7" | ||
}, | ||
"dependencies": { | ||
"@mermaid-chart/mermaid": "11.4.1-b.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this package is public.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is not public and because of this we decided to make vs code plugin repository private.
webview/pnpm-lock.yaml
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please setup PNPM workspace properly, there should only be one pnpm-lock.yaml file.
webview/src/App.svelte
Outdated
.icon:hover { | ||
box-shadow: 0px 0px 4px var(--shadow-color); | ||
background-color: var(--shadow-color); | ||
} | ||
svg { | ||
width: 25px; | ||
height: 25px; | ||
transition: stroke 0.3s, fill 0.3s; | ||
} | ||
.icon.active { | ||
background-color: var(--shadow-color); | ||
box-shadow: 0px 0px 4px var(--shadow-color); | ||
} | ||
|
||
.icon span { | ||
width: 20px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please run prettier on all the files (or setup properly in the repo)
src/commands/createFile.ts
Outdated
} | ||
|
||
const document = activeEditor?.document; | ||
if (document && document?.languageId !== "plaintext" && !document.fileName.endsWith(".mmd") && !document.fileName.endsWith(".mermaid") && !document.languageId.startsWith('mermaid')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document?
is not required if document &&
is already checked.
) | ||
vscode.workspace.onWillSaveTextDocument(async (event) => { | ||
if (event.document.languageId.startsWith("mermaid")) { | ||
event.waitUntil(Promise.resolve([])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onWillSaveTextDocument event is used to sync changes from the local file to Mermaid Chart. The event.waitUntil(Promise.resolve([])) prevents unintended modifications from other extensions (such as formatters or linters), ensuring that the file remains unchanged during the save process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does it do that, can you share some docs for that, and add a comment there?
public async saveDocumentCode(code: string, documentID: string): Promise<MCDocument> { | ||
const response = await this.axios.patch(this.URLS.rest.documents.patch(documentID), { | ||
code: code, | ||
}); | ||
return response.data; | ||
} | ||
public async createDocumentWithDiagram(code: string, projectID: string): Promise<MCDocument> { | ||
const response = await this.axios.post(this.URLS.rest.projects.get(projectID).documents, { | ||
code : code | ||
}); | ||
return response.data; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the mermaidchart SDK instead of custom code.
https://github.com/Mermaid-Chart/plugins/tree/main/packages/sdk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, @sidharthv96. Since the custom API code is already in place, can we create a separate ticket to migrate to the MermaidChart SDK later based on our current priorities?
src/syntaxHighlighter.ts
Outdated
import * as fs from 'fs'; | ||
import * as vscode from 'vscode'; | ||
|
||
export function getFirstWord(text: string): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://github.com/mermaid-js/mermaid/blob/c0187101e9cb3ea9d1966575efcd80ebb6a9a203/packages/mermaid/src/preprocess.ts on how we handle this inside mermaid, the same approach is preferred, instead of custom parsing logic
src/templates/previewTemplate.ts
Outdated
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Svelte Mermaid Preview</title> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<title>Svelte Mermaid Preview</title> | |
<title>Mermaid Preview</title> |
"architecture": [ | ||
"architecture" | ||
], | ||
"packet": [ | ||
"packet" | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't these in beta as well? Double check all the diagrams for beta.
activeEditor.document, | ||
comments | ||
); | ||
let mermaidChartTokens |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add type to this.
}) | ||
); | ||
const syncFileToMermaidChart = async (document: vscode.TextDocument) => { | ||
if (document.languageId.startsWith("mermaid")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Early return.
export function extractIdFromCode(code: string): string | null { | ||
const { frontMatter } = splitFrontMatter(code); | ||
if (!frontMatter) return null; // No frontmatter present | ||
|
||
const document = parseFrontMatterYAML(frontMatter); | ||
const id = document.contents.get('id'); | ||
|
||
return typeof id === 'string' ? id : null; // Ensure 'id' is a string | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use undefined
instead of null
const frontMatterRegex = /^-{3}\s*[\n\r](.*?[\n\r])-{3}\s*[\n\r]+/s; | ||
const YAML_BLOCK_REGEX = /^\s*---[\r\n]+([\s\S]+?)[\r\n]+\s*---/gm; | ||
const EMPTY_BLOCK_REGEX = /^\s*---\s*\n\s*---\s*\n?/; | ||
const COMMENT_REGEX = /^\s*%%(?!{)[^\n]+\n?/gm; | ||
const DIRECTIVE_REGEX = /%{2}{\s*(?:(\w+)\s*:|(\w+))\s*(?:(\w+)|((?:(?!}%{2}).|\r?\n)*))?\s*(?:}%{2})?/gi; | ||
const FIRST_WORD_REGEX = /^\s*(\w+)/; | ||
|
||
export const anyCommentRegex = /\s*%%.*\n/gm; | ||
|
||
function parseFrontMatterYAML(frontMatterYaml: string): Document<YAMLMap, false> { | ||
const document: Document = parseDocument(frontMatterYaml); | ||
if (!isMap(document.contents)) { | ||
document.contents = new YAMLMap(); | ||
} | ||
return document as unknown as Document<YAMLMap, false>; | ||
} | ||
|
||
function splitFrontMatter(text: string) { | ||
const matches = text.match(frontMatterRegex); | ||
if (!matches || !matches[1]) { | ||
return { | ||
diagramText: text, | ||
frontMatter: '', | ||
}; | ||
} else { | ||
return { | ||
diagramText: text.slice(matches[0].length), | ||
frontMatter: matches[1], | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if you can use mermaid's internal functions to parse these, no need to duplicate.
|
||
const element = document.getElementById("mermaid-diagram"); | ||
if (element && diagramContent) { | ||
if (diagramContent === " ") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we checking for an empty space?
const currentPan = panzoomInstance?.getPan() || { x: 0, y: 0 }; | ||
const { svg } = await mermaid.render("diagram-graph", diagramContent); | ||
element.innerHTML = svg; | ||
if (theme && (theme === "dark" || theme === "neo-dark" )) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (theme && (theme === "dark" || theme === "neo-dark" )) { | |
if (theme?.endsWith("dark")) { |
} | ||
|
||
if (isToggled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
if (isToggled) { | |
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed toggle as it is not in use
type: "error", | ||
message: errorMessage, | ||
}); | ||
isErrorOccured = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
isErrorOccured = true | |
hasErrorOccured = true |
<script> | ||
export let fill; | ||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add type